com.sponsorpay.sdk.android.advertiser
Class AsyncAPICaller

java.lang.Object
  extended by 
      extended by com.sponsorpay.sdk.android.advertiser.AsyncAPICaller

public class AsyncAPICaller
extends

Runs in the background the Advertiser Callback HTTP request.


Nested Class Summary
static interface AsyncAPICaller.APIResultListener
          Interface to be implemented by parties interested in the response from the SponsorPay server for the advertiser callback.
 
Field Summary
private static java.lang.String API_PRODUCTION_RESOURCE_URL
          The API resource URL to contact when talking to the Sponsorpay Ad API
private static java.lang.String API_STAGING_RESOURCE_URL
           
private static java.lang.String LANGUAGE_KEY
          The language setting key for the callback URL parameter
private  AdvertiserHostInfo mHostInfo
          Used to extract required information for the host application and device.
private  HttpClient mHttpClient
          The HTTP client employed to call the Sponsorpay API
private  HttpUriRequest mHttpRequest
          The HTTP request that will be executed to contact the API with the callback request
private  HttpResponse mHttpResponse
          The response returned by the SponsorPay API
private  AsyncAPICaller.APIResultListener mListener
          Registered listener for the result of the advertiser callback request.
private static java.lang.String OFFER_ID_KEY
          The offer ID key for the callback URL parameter
private static java.lang.String OS_VERSION_KEY
          The OS version key for the callback URL parameter
private static java.lang.String PHONE_VERSION_KEY
          The phone version key for the callback URL parameter
private static java.lang.String PROGRAM_ID_KEY
           
private static int SUCCESFUL_HTTP_STATUS_CODE
          HTTP status code that the response should have in order to determine that the API has been contacted successfully.
private static java.lang.String UDID_KEY
          The UDID key for the callback URL parameter
 
Constructor Summary
AsyncAPICaller(AdvertiserHostInfo hostInfo, AsyncAPICaller.APIResultListener listener)
           Constructor.
 
Method Summary
protected  java.lang.Boolean doInBackground(AdvertiserHostInfo... params)
           Method overridden from AsyncTask.
protected  void onPostExecute(java.lang.Boolean requestWasSuccessful)
          This method is called by the Android AsyncTask implementation in the UI thread (or the thread which invoked trigger()) when doInBackground(AdvertiserHostInfo...) returns.
 void trigger()
          Triggers the callback request that contacts the Sponsorpay Advertiser API.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUCCESFUL_HTTP_STATUS_CODE

private static final int SUCCESFUL_HTTP_STATUS_CODE
HTTP status code that the response should have in order to determine that the API has been contacted successfully.

See Also:
Constant Field Values

API_PRODUCTION_RESOURCE_URL

private static final java.lang.String API_PRODUCTION_RESOURCE_URL
The API resource URL to contact when talking to the Sponsorpay Ad API

See Also:
Constant Field Values

API_STAGING_RESOURCE_URL

private static final java.lang.String API_STAGING_RESOURCE_URL
See Also:
Constant Field Values

UDID_KEY

private static final java.lang.String UDID_KEY
The UDID key for the callback URL parameter

See Also:
Constant Field Values

OFFER_ID_KEY

private static final java.lang.String OFFER_ID_KEY
The offer ID key for the callback URL parameter

See Also:
Constant Field Values

PROGRAM_ID_KEY

private static final java.lang.String PROGRAM_ID_KEY
See Also:
Constant Field Values

OS_VERSION_KEY

private static final java.lang.String OS_VERSION_KEY
The OS version key for the callback URL parameter

See Also:
Constant Field Values

PHONE_VERSION_KEY

private static final java.lang.String PHONE_VERSION_KEY
The phone version key for the callback URL parameter

See Also:
Constant Field Values

LANGUAGE_KEY

private static final java.lang.String LANGUAGE_KEY
The language setting key for the callback URL parameter

See Also:
Constant Field Values

mHttpRequest

private HttpUriRequest mHttpRequest
The HTTP request that will be executed to contact the API with the callback request


mHttpResponse

private HttpResponse mHttpResponse
The response returned by the SponsorPay API


mHttpClient

private HttpClient mHttpClient
The HTTP client employed to call the Sponsorpay API


mListener

private AsyncAPICaller.APIResultListener mListener
Registered listener for the result of the advertiser callback request.


mHostInfo

private AdvertiserHostInfo mHostInfo
Used to extract required information for the host application and device. This data will be sent on the callback request.

Constructor Detail

AsyncAPICaller

public AsyncAPICaller(AdvertiserHostInfo hostInfo,
                      AsyncAPICaller.APIResultListener listener)

Constructor. Sets the request callback listener and stores the host information.

See AdvertiserHostInfo and AsyncAPICaller.APIResultListener.

Parameters:
hostInfo - the host information for the given device
listener - the callback listener
Method Detail

trigger

public void trigger()
Triggers the callback request that contacts the Sponsorpay Advertiser API. If and when a succesful response is received from the server, the AsyncAPICaller.APIResultListener registered through the constructor AsyncAPICaller(AdvertiserHostInfo, APIResultListener) will be notified.


doInBackground

protected java.lang.Boolean doInBackground(AdvertiserHostInfo... params)

Method overridden from AsyncTask. Executed on a background thread, runs the API contact request.

Encodes the host information in the request URL, runs the request, waits for the response, parses its status code and lets the UI thread receive the result and notify the registered AsyncAPICaller.APIResultListener.

Parameters:
params - Only one parameter of type AdvertiserHostInfo is expected.
Returns:
True for a succesful request, false otherwise. This value will be communicated to the UI thread by the Android AsyncTask implementation.

onPostExecute

protected void onPostExecute(java.lang.Boolean requestWasSuccessful)
This method is called by the Android AsyncTask implementation in the UI thread (or the thread which invoked trigger()) when doInBackground(AdvertiserHostInfo...) returns. It will invoke the registered AsyncAPICaller.APIResultListener

Parameters:
requestWasSuccessful - true if the response has a successful status code (equal to SUCCESFUL_HTTP_STATUS_CODE). false otherwise.